Skip to content

Conversation

@boratanrikulu
Copy link
Member

@boratanrikulu boratanrikulu commented Jan 27, 2026

Summary

  • Fix field name corruption when metrics are re-processed through the Rename processor
  • Add idempotency test to ensure field names remain stable across multiple processing passes

Technical Details

Root Cause

The fallback in Rename.Process() was using ChangeNames(key) where key included the measurement prefix (originalName + "." + field.Key). This caused field names to accumulate prefixes when metrics were re-processed.

Test Results (Before Fix)

Running TestRenameIdempotent shows the corruption accumulating with each pass:

=== RUN   TestRenameIdempotent
    rename_test.go:49: Pass 1: field = "workers.dns"
    rename_test.go:49: Pass 2: field = "apache.workers.dns"
    rename_test.go:49: Pass 3: field = "apache.apache.workers.dns"
    rename_test.go:49: Pass 4: field = "apache.apache.apache.workers.dns"
    rename_test.go:49: Pass 5: field = "apache.apache.apache.apache.workers.dns"
--- FAIL: TestRenameIdempotent

Each pass through the processor adds another "apache." prefix!

The Fix

Use ChangeNames(field.Key) directly instead of ChangeNames(key):

replace, ok := fieldReplaces[key]
if !ok {
    // Use field.Key directly to avoid prepending measurement name.
    // This prevents corruption on re-processing and ensures idempotency.
    replace = ChangeNames(field.Key)
}

Impact

For mapped fields (apache, nginx, mongodb, etc.): No change - they use fieldReplaces mappings as before.

For unmapped fields (e.g., etcd):

BEFORE: measurement="etcd", field="slow_requests" → field becomes "etcd.slow.requests"
AFTER:  measurement="etcd", field="slow_requests" → field becomes "slow.requests"

The fix ensures idempotency: processing a metric multiple times no longer corrupts field names.

Test Plan

  • Update existing test expectation for unmapped field behavior
  • Add TestRenameIdempotent to verify field names remain stable across multiple passes
  • Run full test suite: go test ./plugins/outputs/sematext/...

The fallback in Rename.Process() was using ChangeNames(key) where key
included the measurement prefix. This caused field names to accumulate
prefixes when metrics were re-processed:

  BEFORE: measurement="etcd", field="slow_requests" → "etcd.slow.requests"
  AFTER:  measurement="etcd", field="slow_requests" → "slow.requests"

For mapped fields (apache, nginx, etc.) there is no change - they use
fieldReplaces mappings. The fix ensures idempotency: processing a metric
multiple times no longer corrupts field names.
akshatagarwl
akshatagarwl approved these changes Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants